﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace FrameworkLib.Utilities
{
    public static class ComboBoxHelper
    {
        public static void LoadData(this ComboBox control, string displayMember, string valueMember, object data)
        {
            control.DisplayMember = displayMember;
            control.ValueMember = valueMember;
            control.DataSource = data;
        }

        public static void LoadData(this ComboBox control, string displayMember, string valueMember, object data, object defaultValue)
        {
            if (data == null) return;

            ((IList) data).Insert(0, defaultValue);

            control.DisplayMember = displayMember;
            control.ValueMember = valueMember;
            control.DataSource = data;
        }

        public static void SelectComboItem(ComboBox comboBox, string item)
        {
            if (comboBox.Items.Count > 0)
            {
                comboBox.SelectedIndex = comboBox.FindString(item, -1);
            }
        }
    }
}
